﻿using System;
using System.Windows.Forms;

namespace LD.Host
{
    public partial class FrmVariable : BaseFrm
    {
        public FrmVariable()
        {
            InitializeComponent();
            this.Shown += FrmVariable_Shown;
            this.treeViewY1.ExpandAll();
        }

        private void FrmVariable_Shown(object sender, EventArgs e)
        {
            base.Permission(UserType.管理员);

            Loader();
        }
        private void Loader()
        {
            this.treeViewY1.Nodes.Clear();
            //var list1 = CacheHelper1.Cache;
            //if (list1.Count > 0)
            //{
            //    TreeNode tree = new TreeNode();
            //    tree.Text = "系统";
            //    tree.SelectedImageIndex = 1;
            //    tree.ImageIndex = 0;

            //    foreach (var child in list1)
            //    {
            //        TreeNode tree_child = new TreeNode();
            //        tree_child.Text = child.Key;
            //        tree_child.SelectedImageIndex = 1;
            //        tree_child.ImageIndex = 2;
            //        tree.Nodes.Add(tree_child);
            //    }
            //    this.treeViewY1.Nodes.Add(tree);
            //}
            //var list = CacheHelper.Instance.GetList.Select(p => (p.Value as TB_Variable)).ToList();
            //var main = list.Where(p => p.PId == 0 && !p.IsHide).ToList();
            //foreach (var item in main)
            //{
            //    TreeNode tree = new TreeNode();
            //    tree.Text = item.Name;
            //    tree.SelectedImageIndex = 1;
            //    tree.ImageIndex = 0;

            //    var childs = list.Where(p => p.PId == item.Id && !p.IsHide).ToList();
            //    foreach (var child in childs)
            //    {
            //        TreeNode tree_child = new TreeNode();
            //        tree_child.Text = child.Name;
            //        tree_child.SelectedImageIndex = 1;
            //        tree_child.ImageIndex = 2;
            //        tree.Nodes.Add(tree_child);
            //    }
            //    this.treeViewY1.Nodes.Add(tree);
            //}
        }
        public void New()
        {
            FrmVariableEdit edit = new FrmVariableEdit();
            if (edit.ShowDialog() == DialogResult.OK)
            {
                Loader();
            }
        }
        public void MRefresh()
        {
            Loader();
        }
        private void treeViewY1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            FrmVariableEdit edit = new FrmVariableEdit(e.Node.Text);
            if (edit.ShowDialog() == DialogResult.OK)
            {
                Loader();
            }
        }
    }
}
